package com.lcxsoft.ossservice.controller;

import com.lcxsoft.commonutils.R;
import com.lcxsoft.ossservice.service.OssService;
import com.lcxsoft.ossservice.url.OssServiceURL;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping(OssServiceURL.packageUrl)
public class OssController {

    @Resource
    private OssService ossService;

    /**
     * 上传图片返回图片url
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping(value = OssServiceURL.OssUrl.uploadFile, method = RequestMethod.POST)
    public R uploadFile(MultipartFile file) throws Exception{
        String url =ossService.uploadToOss(file);
        return R.ok().data("url", url);
    }


}
